<?php
error_reporting(E_ALL ^ E_NOTICE);
if(!file_exists("config/install.lock")){
	header("Location:install");exit;
};
header("Content-type:text/html; charset=utf-8");
define("REWRITE_ON",false);//开启伪静态 默认关闭
define("ROOT_PATH",  str_replace("\\", "/", dirname(__FILE__))."/");
@include_once("config/site_list.php");
@include_once("config/setconfig.php");

require(ROOT_PATH."config/config.php");
require(ROOT_PATH."config/const.php");
require(ROOT_PATH."config/version.php");
define("CONTROL_DIR","source/admin");
	define("MODEL_DIR","source/model");
	$template_dir="themes/admin";


$cache_dir="";
$template_dir=$wap_template_dir="themes/admin";
$compiled_dir="";
$html_dir="";

require("./skymvc/skymvc.php");
function userinit(&$base){
	 
	$base->loadConfig("table");
	$base->smarty->assign("config",$base->config_data);	
	$base->smarty->assign("appindex",APPINDEX);
	$base->smarty->assign("appadmin",APPADMIN);
	$base->smarty->assign("appshop",APPSHOP);
	$base->smarty->assign(array(
		"appkucun"=>APPKUCUN,
		"appkoudai"=>APPKOUDAI,
		"appymdian"=>APPYMDIAN
	));
	if(isset($_SESSION['ssadmin']['id'])){
		$base->ssadmin=$_SESSION['ssadmin'];//当前登录用户的信息
		
		if($_SESSION['ssadmin']['isfounder'] ){
			if(get_post('setsite')){
				$_SESSION['ssadmin']['siteid']=get_post('siteid','i');
			}
		}else if($_SESSION['ssadmin']['cityid']>0 ){
			//判断权限
			$sid=get_post('siteid','i');
			$siteids=M("sites")->getIdsByCity(intval($_SESSION['ssadmin']['cityid']));
			if(in_array($sid,$siteids)){
				$_SESSION['ssadmin']['siteid']=$sid;
			}
		}
		$base->smarty->assign("ssadmin",$base->ssadmin);
		$base->smarty->assign("site",m("sites")->selectRow(array("where"=>array("siteid"=>intval($_SESSION['ssadmin']['siteid'])))));
	}
	if(!in_array(get('m'),array('login',"checkcode","backup","user"))){
		session_write_close();
	}
	$base->smarty->assign(array(
		"skins"=>"/themes/admin/",
		"skinsadmindir"=>"themes/admin",
	)); 
	$base->smarty->assign("appadmin",APPADMIN);
	$m=get('m','h');
	$s=M("sites")->selectRow(array(
		"order"=>" siteid ASC",
		"where"=>" status < 11 ",
		"limit"=>1
	));
	 
	define("SITEID",max($s['siteid'],$_SESSION['ssadmin']['siteid'])); 
	
	//define("SITEID",max(1,$_SESSION['ssadmin']['siteid'])); 
	if(!in_array($m,array('login'))){
		if(!isset($_SESSION['ssadmin']['id'])){
			$base->gourl(APPADMIN."?m=login");
		}
		M("admin_log")->insert(array(
			"dateline"=>time(),
			"adminid"=>$_SESSION['ssadmin']['id'],
			"content"=>base64_encode(json_encode($_REQUEST)),
			"m"=>get_post('m','h'),
			"a"=>get_post('a','h'),
			"ip"=>ip()
		));
		define("ADMINGID",intval($_SESSION['ssadmin']['group_id']));
		define("ADMINCITYID",$_SESSION['ssadmin']['cityid']);
		if(ADMINGID==1){
			$GLOBALS['sw']=" 1 ";
		}elseif(ADMINGID==2){
			 
			$siteids=M("sites")->getIdsByCity(ADMINCITYID);
			if($siteids){
				$GLOBALS['sw']=" siteid in("._implode($siteids).")";
			}else{
				$GLOBALS['sw']=" 1=2 ";
			}
		}else{
			$GLOBALS['sw']=" siteid=".SITEID;
		}
		$permission=unserialize(m("admin_group")->selectOne(array("where"=>array("id"=>$_SESSION['ssadmin']['group_id']),"fields"=>"content")));
		if(!$base->checkpermission($permission) && !$_SESSION['ssadmin']['isfounder'] ){			 
			$base->gomsg("您无权限",APPADMIN."?m=iframe&a=main");
			
		}
	}	
}

?>